<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="采购方总部编码，国家电网：sgcc" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserHqCode', validatorRules.purchaserHqCode]" placeholder="请输入采购方总部编码，国家电网：sgcc"></a-input>
        </a-form-item>
        <a-form-item label="订单类型; 0,平柜，装置
" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipoType', validatorRules.ipoType]" placeholder="请输入订单类型; 0,平柜，装置
"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="生产订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipoNo', validatorRules.ipoNo]" placeholder="请输入生产订单号"></a-input>
        </a-form-item>
        <a-form-item label="品类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryCode', validatorRules.categoryCode]" placeholder="请输入品类编码"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclassCode', validatorRules.subclassCode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="销售订单号或销售订单行目号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soNo', validatorRules.soNo]" placeholder="请输入销售订单号或销售订单行目号"></a-input>
        </a-form-item>
        <a-form-item label="厂家物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsCode', validatorRules.materialsCode]" placeholder="请输入厂家物料编码"></a-input>
        </a-form-item>
        <a-form-item label="厂家物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsName', validatorRules.materialsName]" placeholder="请输入厂家物料名称"></a-input>
        </a-form-item>
        <a-form-item label="厂家物资单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsUnit', validatorRules.materialsUnit]" placeholder="请输入厂家物资单位"></a-input>
        </a-form-item>
        <a-form-item label="厂家物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsDesc', validatorRules.materialsDesc]" placeholder="请输入厂家物料描述"></a-input>
        </a-form-item>
        <a-form-item label="生产数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'amount', validatorRules.amount]" placeholder="请输入生产数量"></a-input>
        </a-form-item>
        <a-form-item label="计量单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'unit', validatorRules.unit]" placeholder="请输入计量单位"></a-input>
        </a-form-item>
        <a-form-item label="物资id分组" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productIdGrpNo', validatorRules.productIdGrpNo]" placeholder="请输入物资id分组"></a-input>
        </a-form-item>
        <a-form-item label="物资id类型，采购方侧，如国网侧" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productIdType', validatorRules.productIdType]" placeholder="请输入物资id类型，采购方侧，如国网侧"></a-input>
        </a-form-item>
        <a-form-item label="产品型号，供应方侧" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productModel', validatorRules.productModel]" placeholder="请输入产品型号，供应方侧"></a-input>
        </a-form-item>
        <a-form-item label="计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planStartDate', validatorRules.planStartDate]" placeholder="请输入计划开始时间"></a-input>
        </a-form-item>
        <a-form-item label="计划完成日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planFinishDate', validatorRules.planFinishDate]" placeholder="请输入计划完成日期"></a-input>
        </a-form-item>
        <a-form-item label="实际开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'actualStartDate', validatorRules.actualStartDate]" placeholder="请输入实际开始时间"></a-input>
        </a-form-item>
        <a-form-item label="实际完成日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'actualFinishDate', validatorRules.actualFinishDate]" placeholder="请输入实际完成日期"></a-input>
        </a-form-item>
        <a-form-item label="生产工厂id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'plantId', validatorRules.plantId]" placeholder="请输入生产工厂id"></a-input>
        </a-form-item>
        <a-form-item label="生产订单编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'plantCode', validatorRules.plantCode]" placeholder="请输入生产订单编码"></a-input>
        </a-form-item>
        <a-form-item label="生产工厂名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'plantName', validatorRules.plantName]" placeholder="请输入生产工厂名称"></a-input>
        </a-form-item>
        <a-form-item label="生产车间id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workShopId', validatorRules.workShopId]" placeholder="请输入生产车间id"></a-input>
        </a-form-item>
        <a-form-item label="生产车间名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workShopName', validatorRules.workShopName]" placeholder="请输入生产车间名称"></a-input>
        </a-form-item>
        <a-form-item label="生产订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipoStatus', validatorRules.ipoStatus]" placeholder="请输入生产订单状态"></a-input>
        </a-form-item>
        <a-form-item label="生产中心" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'center', validatorRules.center]" placeholder="请输入生产中心"></a-input>
        </a-form-item>
        <a-form-item label="工艺路线编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRouteNo', validatorRules.processRouteNo]" placeholder="请输入工艺路线编码"></a-input>
        </a-form-item>
        <a-form-item label="工艺路线" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRoute', validatorRules.processRoute]" placeholder="请输入工艺路线"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSource', validatorRules.dataSource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSourceCreateTime', validatorRules.dataSourceCreateTime]" placeholder="请输入来源数据创建时间"></a-input>
        </a-form-item>
        <a-form-item label="逻辑删除，1.是，0，否" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isDeleted', validatorRules.isDeleted]" placeholder="请输入逻辑删除，1.是，0，否"></a-input>
        </a-form-item>
        <a-form-item label="产品型号规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modelSpec', validatorRules.modelSpec]" placeholder="请输入产品型号规格"></a-input>
        </a-form-item>
        <a-form-item label="是否监造标志，0：否，1：是" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supervisionFlag', validatorRules.supervisionFlag]" placeholder="请输入是否监造标志，0：否，1：是"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  
  export default {
    name: "ZxjEipScddModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        purchaserHqCode:{rules: [{ required: true, message: '请输入采购方总部编码，国家电网：sgcc!' }]},
        ipoType:{rules: [{ required: true, message: '请输入订单类型; 0,平柜，装置!' }]},
        supplierCode:{rules: [{ required: true, message: '请输入供应商编码!' }]},
        ipoNo:{rules: [{ required: true, message: '请输入生产订单号!' }]},
        categoryCode:{rules: [{ required: true, message: '请输入品类编码!' }]},
        subclassCode:{rules: [{ required: true, message: '请输入种类编码!' }]},
        soNo:{rules: [{ required: true, message: '请输入销售订单号或销售订单行目号!' }]},
        materialsCode:{rules: [{ required: true, message: '请输入厂家物料编码!' }]},
        materialsName:{rules: [{ required: true, message: '请输入厂家物料名称!' }]},
        materialsUnit:{rules: [{ required: true, message: '请输入厂家物资单位!' }]},
        materialsDesc:{rules: [{ required: true, message: '请输入厂家物料描述!' }]},
        amount:{rules: [{ required: true, message: '请输入生产数量!' }]},
        unit:{rules: [{ required: true, message: '请输入计量单位!' }]},
        productIdGrpNo:{rules: [{ required: true, message: '请输入物资id分组!' }]},
        productIdType:{},
        productModel:{},
        planStartDate:{rules: [{ required: true, message: '请输入计划开始时间!' }]},
        planFinishDate:{rules: [{ required: true, message: '请输入计划完成日期!' }]},
        actualStartDate:{},
        actualFinishDate:{},
        plantId:{},
        plantCode:{},
        plantName:{},
        workShopId:{},
        workShopName:{},
        ipoStatus:{rules: [{ required: true, message: '请输入生产订单状态!' }]},
        center:{},
        processRouteNo:{rules: [{ required: true, message: '请输入工艺路线编码!' }]},
        processRoute:{rules: [{ required: true, message: '请输入工艺路线!' }]},
        dataSource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        dataSourceCreateTime:{rules: [{ required: true, message: '请输入来源数据创建时间!' }]},
        isDeleted:{rules: [{ required: true, message: '请输入逻辑删除，1.是，0，否!' }]},
        modelSpec:{},
        supervisionFlag:{},
        },
        url: {
          add: "/zxjeipscdd/zxjEipScdd/add",
          edit: "/zxjeipscdd/zxjEipScdd/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'purchaserHqCode','ipoType','supplierCode','ipoNo','categoryCode','subclassCode','soNo','materialsCode','materialsName','materialsUnit','materialsDesc','amount','unit','productIdGrpNo','productIdType','productModel','planStartDate','planFinishDate','actualStartDate','actualFinishDate','plantId','plantCode','plantName','workShopId','workShopName','ipoStatus','center','processRouteNo','processRoute','dataSource','dataSourceCreateTime','isDeleted','modelSpec','supervisionFlag'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'purchaserHqCode','ipoType','supplierCode','ipoNo','categoryCode','subclassCode','soNo','materialsCode','materialsName','materialsUnit','materialsDesc','amount','unit','productIdGrpNo','productIdType','productModel','planStartDate','planFinishDate','actualStartDate','actualFinishDate','plantId','plantCode','plantName','workShopId','workShopName','ipoStatus','center','processRouteNo','processRoute','dataSource','dataSourceCreateTime','isDeleted','modelSpec','supervisionFlag'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>